package pers.whj.rpc.protocol;

/**
 * 表示RPC请求的返回类
 */
public class Response {
    /**
     * 请求成功
     */
    public static final int CODE_SUCCESS = 0;
    /**
     * 请求失败
     */
    public static final int CODE_ERROR = 1;
    /**
     * 未知请求的序号
     */
    public static final long UNKNOWN_SOURCE = -1;
    private int code = CODE_SUCCESS;
    private String errorMsg = "";
    private Object data;//返回数据
    private long number;

    public Response() {
    }

    public Response(long number) {
        this.number = number;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public long getNumber() {
        return number;
    }

    public void setNumber(long number) {
        this.number = number;
    }

    @Override
    public String toString() {
        String str = "{code:" + this.code;
        if (this.code == CODE_SUCCESS) {
            str = str + " data:" + this.data.toString() + "}";
        } else {
            str = str + " error message:" + this.errorMsg + "}";
        }
        return str;
    }
}
